package com.qf.servlet;

import com.qf.service.BookService;
import com.qf.service.impl.BookServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 孙亚梅
 * @version V1.0
 * @Project bookApp-homework
 * @Package ${PACKAGE_NAME}
 * @Description: ${TODO}
 * @Date 2022/5/14 19:48
 */
@WebServlet(name = "DeleteServlet",urlPatterns = "/deleteBook")
public class DeleteServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");

        //通过bookid 删除书籍
        String bookId = request.getParameter("bookId");

        BookService bookService = new BookServiceImpl();
        bookService.deleteBook(bookId);

        //删除之后 重新刷新列表
        response.sendRedirect(request.getContextPath()+"/bookList");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doPost(request, response);
    }
}
